using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;

namespace FernUniHagen.CompilerExtension.DataStructures
{
    /// <summary>
    /// Datastructure to save the mappings of oldexpressions and their replacements within a statement 
    /// </summary>
    public class StatementReplacement<T> where T : CommonSyntaxNode
    {
        #region members
        /// <summary>
        /// Espacially for statements within a block it is necessary to 
        /// not replace only the node, but to add some additional statements before the node. these statements go in here
        /// </summary>
        private List<StatementSyntax> _additionalStatements;
        /// <summary>
        /// The old syntax node which needs to be replaced
        /// </summary>
        private T _oldSyntaxNode;
        /// <summary>
        /// The new syntax node which will be added
        /// </summary>
        private T _newSyntaxNode;
        #endregion

        #region properties

        /// <summary>
        /// The new syntax node which will be added
        /// </summary>
        public List<StatementSyntax> AdditionalStatements
        {
            get { return _additionalStatements; }
            set { _additionalStatements = value; }
        }

        /// <summary>
        /// The new syntax node which will be added
        /// </summary>
        public T OldSyntaxNode
        {
            get { return _oldSyntaxNode; }
            set { _oldSyntaxNode = value; }
        }

        /// <summary>
        /// The old syntax node which needs to be replaced
        /// </summary>
        public T NewSyntaxNode
        {
            get { return _newSyntaxNode; }
            set { _newSyntaxNode = value; }
        }

        #endregion

        #region constructors
        public StatementReplacement()
        {
            _additionalStatements = new List<StatementSyntax>();
        }

        public StatementReplacement(T oldSyntaxNode, T newSyntaxNode) :this()
        {
            OldSyntaxNode = oldSyntaxNode;
            NewSyntaxNode = newSyntaxNode;
        }

        public StatementReplacement(List<StatementSyntax> additionalStatements, T oldSyntaxNode, T newSyntaxNode) : this(oldSyntaxNode,newSyntaxNode)
        {
            _additionalStatements = additionalStatements;
        }
        #endregion

    }
}
